﻿using System;
using System.Windows.Forms;

namespace ExtractItAll.Forms
{
  public partial class PasswordManager : UserControl
  {
    //private bool _updating = false;
    //public Password CurrentPassword
    //{
    //  get
    //  {
    //    if (passwordListView.FocusedItem == null) return null;
    //    if (passwordListView.FocusedItem.Tag == null) return null;
    //    return passwordListView.FocusedItem.Tag as Password;
    //  }
    //}

    public PasswordManager()
    {
      InitializeComponent();

      //set datasource
      passwordBindingSource.DataSource = Program.Passwords.Items;
      //RefreshPasswords(false);
    }

    //private void RefreshPasswords(bool forceRefresh)
    //{
    //  //if (!forceRefresh && splitContainer1.Panel2Collapsed) return;

    //  passwordListView.BeginUpdate();
    //  passwordListView.Items.Clear();
    //  foreach (Password password in Program.Passwords.Items)
    //  {
    //    ListViewItem item = new ListViewItem();
    //    item.Text = password.Text;
    //    item.SubItems.Add(password.Count.ToString());
    //    item.Tag = password;

    //    passwordListView.Items.Add(item);
    //  }
    //  passwordListView.EndUpdate();
    //}

    //private void passwordListView_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //  if (CurrentPassword == null) return;

    //  _updating = true;

    //  setCounterTextBox.Text = CurrentPassword.Text;
    //  setCounterNumericUpDown.Value = CurrentPassword.Count;

    //  removePasswordTextBox.Text = CurrentPassword.Text;

    //  _updating = false;
    //}

    private void addPasswordButton_Click(object sender, EventArgs e)
    {
      Program.Passwords.Add(addPasswordTextBox.Lines);
      addPasswordTextBox.Text = String.Empty;

      dataGridView1.Refresh();
    }

    private void passwordBindingSource_CurrentChanged(object sender, EventArgs e)
    {
      Program.Passwords.Sort();
      dataGridView1.Refresh();
    }


    //private void setCounterNumericUpDown_ValueChanged(object sender, EventArgs e)
    //{
    //  if (CurrentPassword == null) return;
    //  if (_updating) return;

    //  Program.Passwords.SetCounter(
    //    CurrentPassword.Text,
    //    (int)setCounterNumericUpDown.Value);

    //  RefreshPasswords(false);
    //}

    //private void removePasswordButton_Click(object sender, EventArgs e)
    //{
    //  if (CurrentPassword == null) return;

    //  Program.Passwords.Remove(CurrentPassword.Text);

    //  RefreshPasswords(false);
    //}
  }
}